package com.macasa.panel.entity.impl;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import com.google.common.base.Objects;
import com.macasa.enumerations.PowerDnsDomainRecordType;
import com.macasa.panel.common.utils.CastHelpers;
import com.macasa.panel.entity.api.AbstractModel;
import com.macasa.panel.entity.api.IPowerDnsServiceDomain;
import com.macasa.panel.entity.api.IPowerDnsServiceDomainRecord;

@Entity
@Table(name = "power_dns_service_domain_record")
@SequenceGenerator(name = "PowerDnsServiceDomainRecord_SEQ", sequenceName = "PowerDnsServiceDomainRecordIdSeq", initialValue = 1)
@Getter
@Setter
@ToString
public class PowerDnsServiceDomainRecord extends AbstractModel<Integer> implements IPowerDnsServiceDomainRecord {

	/**
	 * The Constant serialVersionUID
	 */
	@Version
	private static final long			serialVersionUID	= -2491888919944290581L;

	@Id
	@Column(name = "power_dns_service_domain_record_id", nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "PowerDnsServiceDomainRecord_SEQ")
	private Integer						id;

	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, targetEntity = com.macasa.panel.entity.impl.PowerDnsServiceDomain.class)
	@JoinColumn(name = "fk_power_dns_service_domain_id", nullable = false)
	private IPowerDnsServiceDomain		powerDnsServiceDomain;

	@Column(name = "name", nullable = false)
	private String						name;

	@Enumerated(EnumType.STRING)
	@Column(name = "type", nullable = false)
	private PowerDnsDomainRecordType	type;

	@Column(name = "content", nullable = false)
	private String						content;

	@Column(name = "ttl", nullable = false)
	private Integer						ttl;

	@Override
	public boolean equals(final Object obj) {

		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof PowerDnsServiceDomainRecord)) {
			return false;
		}

		final PowerDnsServiceDomainRecord other = CastHelpers.cast(obj, PowerDnsServiceDomainRecord.class);

		return Objects.equal(this.id, other.id) && Objects.equal(this.powerDnsServiceDomain, other.powerDnsServiceDomain)
				&& Objects.equal(this.name, other.name) && Objects.equal(this.type, other.type) && Objects.equal(this.content, other.content)
				&& Objects.equal(this.ttl, other.ttl);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(this.id, this.powerDnsServiceDomain, this.name, this.type, this.content, this.ttl);
	}
}
